package com.woniuxy.microsyslogserver.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.bean.SystemLogBean;
import com.woniuxy.microsyslogserver.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description: 系统操作日志表现层
 *
 * @Auther: HanLei
 * @Date: 2021/4/9:16:12
 */
@RefreshScope
@Api(tags = "系统操作日志查询接口")
@RestController
@RequestMapping(value = "/log", produces = {"application/json;charset=utf-8"})
public class SysLogController {

    @Resource
    private SysLogService sysLogServiceImpl;

    @ApiOperation("根据筛选实体查询所有系统操作日志")
    @PostMapping("/getAllLog/{pageNum}/{pageSize}")
    public ResultBean selectAllLog (@ApiParam("日志筛选对象") @RequestBody SystemLogBean systemLogBean,
                                @ApiParam("当前页码") @PathVariable(value = "pageNum", required = false) int pageNum,
                                @ApiParam("每页数据条数") @PathVariable(value = "pageSize", required = false) int pageSize) {
        if (pageNum == 0) {
            pageNum = 1;
        }
        if (pageSize == 0) {
            pageSize = 10;
        }
        PageInfo<SystemLogBean> logBeans = sysLogServiceImpl.queryAll(systemLogBean, pageNum, pageSize);
        if (logBeans != null) {
            return ResultBean.builder().code(200).msg("查询成功!").data(logBeans).build();
        } else {
            return ResultBean.builder().code(500).msg("系统繁忙，请稍后重试!").build();
        }
    }
}
